﻿define([],function(){
	return {
		setCookie:function (key,val,exp){
			var now=new Date();
			now.setDate(now.getDate()+exp);
			document.cookie=key+"="+val+";expires="+now;
		},
		getCookie:function (key){
			var str=document.cookie;
			var arr=str.split("; ");
			for(var i in arr){
				var k=arr[i].split("=");
				if(k[0]==key){
					return k[1];
				}
			}
			return "";
		},
		getpageCoord:function (ele){
			var totalX = 0;
			var totalY = 0;
			totalX += ele.offsetLeft;
			totalY += ele.offsetTop;
			while(ele.offsetParent){
				ele = ele.offsetParent;
				totalX += ele.offsetLeft;
				totalY += ele.offsetTop;
			}
			return {
				x : totalX,
				y : totalY
			};
		},
		getStyle:function (ele){
			if(ele.currentStyle){
				return ele.currentStyle;
			}else{
				return getComputedStyle(ele,null);
			}
		},
		getchildNodes:function (ele){
			var newlist=[];
			for(var i=0;i<ele.childNodes.length;i++){
				if(ele.childNodes[i].nodeType==1){
					newlist.push(ele.childNodes[i]);
				}
			}
			return newlist;
		},
		randomInt:function (min, max){
			return Math.round(Math.random()*(max-min)) + min;
		},
		randomcolor:function (){
			var R=this.randomInt(0,255).toString(16);
			var G=this.randomInt(0,255).toString(16);
			var B=this.randomInt(0,255).toString(16);
			
			return "#"+(R.length<2?"0"+R:R)+(G.length<2?"0"+G:G)+(B.length<2?"0"+B:B);
		},
		date2string:function (d, sep, yaobuyao){
			sep = sep || "-";
			var str = d.getFullYear()+sep+(d.getMonth()+1)+sep+d.getDate(); 
			if(yaobuyao){
				str += " "+d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
				return str;
			} else {
				return str;
			}
		},
		string2date:function (str, sep){
			str = str.replace(sep, "-");
			return new Date(str);
		},
		between:function (start, end, isfix){
			var total = Math.abs(start.getTime()-end.getTime())/1000;
			return isfix ? Math.round(total/(24*3600)) : total/(24*3600);
		}
	}	
})




